<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('设备营业额列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <input type="hidden" id="storeId" name="storeId" th:value="${storeId}">
                        <li>
                            <label>设备类型：</label>
                            <select name="devType" th:with="type=${@dict.getType('sys_device_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li class="select-time">
                            <label>时间筛选：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="startTime"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="endTime"/>
                        </li>
                        <li>
                            <label style="width: 105px;">关键字查询字段：</label>
                            <select name="fields">
                                <option value="sn" selected>机柜SN</option>
                                <option value="merchantFullName">商户姓名</option>
                                <option value="storeName">门店名</option>
                            </select>
                            <input type="text" name="keywords"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">

    var devTypeDatas = [[${@dict.getType('sys_device_type')}]];
    var devStatusDatas = [[${@dict.getType('sys_device_status')}]];
    var prefix = ctx + "system/device";

    $(function () {
        var options = {
            url: prefix + "/listDevIncome",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "设备营业额",
            showFooter: true,
            queryParams: queryParams,
            footerStyle: footerStyle,
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '',
                    visible: false
                },
                {
                    field: 'sn',
                    title: '机柜SN(设备状态)',
                    formatter: function (value, row, index) {
                        return value + "<span style='color: green;'>(" + $.table.selectDictLabel(devStatusDatas, row.devStatus) + ")</span>";
                    }
                },
                {
                    field: 'devType',
                    title: '设备类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(devTypeDatas, value);
                    }
                },
                {
                    field: 'amountPaidSum',
                    title: '设备营业额',
                    footerFormatter:function (value) {
                        var amountPaidSum = 0;
                        for (var i in value) {
                            amountPaidSum += parseFloat(value[i].amountPaidSum);
                        }
                        return "总金额：" + amountPaidSum;
                    }
                },
                {
                    field: 'merchantFullName',
                    title: '直营商户'
                },
                {
                    field: 'storeName',
                    title: '门店名'
                },
            ]
        };
        $.table.init(options);
    });

    function queryParams(params) {
        var search = $.table.queryParams(params);
        search.storeId = $("#storeId").val();
        return search;
    }

    function footerStyle(column) {
        return {
            amountPaidSum: {
                css: { color: 'red', 'font-weight': 'normal' }
            }
        }[column.field]
    }

</script>
</body>
</html>